#include "RadialAccelerator.h"

RadialAccelerator::RadialAccelerator()
{
	effectiveAcceleration = 0;
	effectiveRadius = 0;
	effectiveRadiusSquared = 0;
	active = false;
	global = false;
}

RadialAccelerator::RadialAccelerator(float a, float r)
{
	effectiveAcceleration = a;
	effectiveRadius = r;
	effectiveRadiusSquared = r*r;
	active = false;
	global = false;
}

void RadialAccelerator::affect(Entity *entity)
{
	Vec2d disp = this->pos - entity->pos;
	float r2 = disp*disp;
	if (global || r2 < effectiveRadiusSquared)
		entity->accel = entity->accel + disp.normalize() * effectiveAcceleration;
}

float RadialAccelerator::getEffectiveRadius()
{
	return effectiveRadius;
}

void RadialAccelerator::setEffectiveRadius(float r)
{
	this->effectiveRadius = r;
	this->effectiveRadiusSquared = r * r;
}